﻿using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Diagnostics;
namespace KeyGame_and_PrimeNumeber
{
    internal class Program
    {
        const int Length = 20;
        /// <summary>
        /// 1.按键小游戏：随机给出提示，要求用户按键，重复N次，要求统计总用时及出错次数
        /// </summary>
        /// <param name="args"></param>
        enum Direction { Up, Down, Left, Right };
        static void Main(string[] args)
        {
            //1.按键小游戏
            //给出随机提示
            var rand = new Random();
            //定义错误次数
            int i = 0;
            int error = 0;         
            //定义计时工具 统计总用时
            var watch = Stopwatch.StartNew();   
            bool flag= false;
            //统计出错次数
            for(i=1;i<=Length;i++)
            {
                do
                {
                    Console.Clear();       
                    //创建随机变量
                    Direction direction = (Direction)rand.Next(0, 4);
                    Console.Write(direction);
                    //接受用户按键输入
                    var input = Console.ReadKey();
                    //判断用户输入与随机变量是否一致
                    switch (direction)
                    {
                        case Direction.Up:
                            if (input.Key==ConsoleKey.UpArrow)
                                flag = true;
                            else
                                error++;
                                break;
                        case Direction.Down:
                            if (input.Key == ConsoleKey.DownArrow)
                                flag = true;
                            else
                                error++;
                            break;
                        case Direction.Left:
                            if (input.Key == ConsoleKey.LeftArrow)
                                flag = true;
                            else
                                error++;
                            break;
                        case Direction.Right:
                            if (input.Key == ConsoleKey.RightArrow)
                                flag = true;
                            else
                                error++;
                            break;
                        default:
                            break;
                    }                   
                    Console.WriteLine($"您一共进行了{i}次；您的错误次数为：{error}次");
                    Console.WriteLine($"您的总耗时为：{watch.Elapsed}");
                    Console.ReadKey();
                } //若不正确则重新输入
                while (flag==false);                
            }
        }       
    }
}